import { StatusBar, StyleSheet, useColorScheme, View } from 'react-native';
import { WebView } from 'react-native-webview';
import React, { useEffect, useState } from 'react';
import { getDictByKey } from '@api/base';
// import HomeTab from './pages/HomeTab';

function App() {
  const isDarkMode = useColorScheme() === 'dark';
  const [webviewSource, setWebviewSource] = useState({
    uri: 'https://interview.mychat.ink',
  });

  useEffect(() => {
    getDictByKey('ls_link')
      .then((res: any) => {
        if (res?.data?.url) {
          setWebviewSource({ uri: res?.data?.value?.url || '' });
        }
      })
      .catch(error => {
        console.log('Failed to get ls_link data:', error);
      });
  }, []);

  return (
    <View style={styles.container}>
      <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
      <WebView
        source={webviewSource}
        style={styles.webview}
        javaScriptEnabled={true}
        domStorageEnabled={true}
        startInLoadingState={true}
      />
      {/* <HomeTab /> */}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  webview: {
    flex: 1,
  },
});

export default App;
